use std::fmt;

use crate::reservation::Status;

// reservation status 转 string
impl fmt::Display for Status {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Status::Unknown => write!(f, "unknown"),
            Status::Pending => write!(f, "pending"),
            Status::Confirmed => write!(f, "confirmed"),
            Status::Blocked => write!(f, "blocked"),
        }
    }
}

// 将数据库中的status字段映射成该enum
#[derive(Debug, Clone, Copy, PartialEq, Eq, sqlx::Type)]
#[sqlx(type_name = "reservation_status", rename_all = "lowercase")]
pub enum RsvpStatus {
    Unknown,
    Pending,
    Confirmed,
    Blocked,
}

// 将RsvpStatus 转成 Status
impl From<RsvpStatus> for Status {
    fn from(status: RsvpStatus) -> Self {
        match status {
            RsvpStatus::Unknown => Self::Unknown,
            RsvpStatus::Pending => Self::Pending,
            RsvpStatus::Confirmed => Self::Confirmed,
            RsvpStatus::Blocked => Self::Blocked,
        }
    }
}
